define([], function() {
	return function(content, loading) {
		var token = localStorage.getItem("token");
		loading.hide();

		var form = content.find("form");

		loading = weui.loading("获取数据中");

		$.post(
			"cls/list.do",
			function(data) {
				var sel = form.find("select[name='classId']");
				$.each(data, function() {
					var o = $("<option></option>");
					o.text(this.className);
					o.val(this.classId);
					sel.append(o);
				});

				$.post(
					"user/get.do", {
						"token": token
					},
					function(data) {
						loading.hide();
						if(data.ok) {
							if(data.user != null) {
								$.each(data.user, function(name, value) {
									form.find("[name='" + name + "']").val(value);
								});
							}
						} else {
							weui.topTips(data.message);
						}
					}, "json"
				);

			}, "json"
		);

		form.submit(function(e) {
			loading = weui.loading("数据提交中");
			var ps = form.serializeArray();
			ps.push({
				name: "token",
				value: token
			});
			$.post(
				"user/save.do",
				ps,
				function(data) {
					loading.hide();
					if(data.ok) {
						weui.toast('保存成功', 1000);
					} else {
						weui.topTips(data.message);
					}
				}, "json"
			);

			return false;
		});

		content.find("._exit").click(function() {
			weui.confirm('确定要退出系统吗', function() {
				loading = weui.loading("系统退出中");
				$.post(
					"user/logout.do", {
						"token": token
					},
					function(data) {
						loading.hide();
						if(data.ok) {
							localStorage.removeItem("token");
							weui.toast('退出成功', {
								duration: 1000,
								callback: function() {
									window.location.replace("login.html");
								}
							});
						} else {
							weui.topTips(data.message);
						}
					}, "json"
				);

			}, function() {

			}, {
				title: '退出确认'
			});
		});
		
		
		
		
		
		

	}
});